unit oposutils;

interface
uses
  Classes,
  Windows,
  Registry;

function getLDN(Value: String; Instance: Integer=1): String;

implementation

function getLDN(Value: String; Instance: Integer=1): String;
var
  tmpReg: TRegistry;
  tmpTS: TStringList;
begin
  Result := '';

  tmpReg := TRegistry.Create;
  try
    tmpReg.RootKey := HKEY_LOCAL_MACHINE;
    if tmpReg.OpenKey(Value, False) then begin //'\SOFTWARE\OLEforRetail\ServiceOPOS\POSPrinter', False) then begin
      tmpTS := TStringList.Create;
      try
        tmpReg.GetKeyNames(tmpTS);

        case Instance of
          1: begin
            if tmpTS.Count > 0 then begin
              if tmpReg.OpenKey(tmpTS[0], False) then begin
                Result := tmpReg.ReadString('DeviceName');
              end;
            end;
          end;

          2: begin
            if tmpTS.Count > 1 then begin
              if tmpReg.OpenKey(tmpTS[1], False) then begin
                Result := tmpReg.ReadString('DeviceName');
              end;
            end;
          end;
        end;

      finally
        tmpTS.Free;
      end;
    end;
  finally
    tmpReg.Free;
  end;

end;

end.
